/**
 * Author: Shen Yanqiu
 * Date: 2018-02-26
 * Time: 15:59
 *
 */
import modelExtend from 'dva-model-extend';
import {pageModel} from '../../common';
import {message} from 'antd';
import {delay, routerTool} from "utils";

export default modelExtend(pageModel, {
  namespace: 'recruitnewStatisticsPersonDetails',
  state: {},
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {
        if (location.pathname === routerTool.getPathByName('RecruitnewStatisticsPersonDetails')) {
          dispatch({ type: 'firstLoad' });
        }
      });
    },
  },
  effects: {
    * firstLoad ({ payload = {} }, { put, call }) {
      yield put({
        type: 'loadTableList',
        payload: {
          current: 0,
          pageSize: 10,
        },
      });
      yield delay(1000);
    },
    * loadTableList ({ payload = {} }, { put, call }) {
      const data = {
        total: 23,
        list: [{
          id: 1,
          username: "小星星",
          department: "新闻部",
          contactWay: "18483661453",
          sex: "0",
        }, {
          id: 2,
          username: "小拳拳",
          department: "宣传部",
          contactWay: "18228202720",
          sex: "0",
        }],
      };
      yield put({
        type: 'loadSuccess',
        payload: {
          list: data.list,
          pagination: {
            current: payload.current,
            pageSize: payload.pageSize,
            total: data.total,
          },
        },
      });
      yield delay(1000);
    },
    * searchData ({ payload: { formData } }, { put, call }) {
      console.log(formData);
    },
    * exportData ({ payload = {} }, { put, call }) {
      console.log(111);
    },
  },
  reducers: {},
});
